home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / feel0_89.lha / Feel / Src / system_t.h < prev    next >
C/C++ Source or Header  |  1993-06-29  |  5KB  |  172 lines

  1. /* ******************************************************************** */
  2. /* system.h          Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Environment specific code                                           */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  
  9.  * System specific types...
  10.  *
  11.  * (see '.c' for details)
  12.  
  13.  */
  14.  
  15. #ifndef SYSTEM_T_H
  16.  
  17. #define SYSTEM_T_H
  18.  
  19. /*
  20.  
  21.  * Types and declarations...
  22.  
  23.  */
  24.  
  25. /* ******************************************************************** */
  26. /*                             System V                                 */
  27. /* ******************************************************************** */
  28.  
  29. #ifdef MACHINE_SYSTEMV
  30.  
  31. #include <sys/types.h>
  32. #include <sys/ipc.h>
  33. #include <sys/sem.h>
  34. #include <sys/shm.h>
  35.  
  36. extern char *shmat(int,char *,int);
  37.  
  38. typedef int SystemSemaphore;
  39.  
  40. #define SYSTEM_THREAD_SPECIFIC_DECLARATION(type,name) type name
  41. #define SYSTEM_THREAD_SPECIFIC_VALUE(name)            (name)
  42.  
  43. #define SYSTEM_GLOBAL(type,name)            volatile type* name
  44. #define SYSTEM_INITIALISE_GLOBAL(type,name,value) \
  45.           (name=(volatile type*)(system_static_malloc(sizeof(type))),*name=value)
  46. #define SYSTEM_GLOBAL_VALUE(name)           (*(name))
  47. #define SYSTEM_GLOBAL_ARRAY1(type,name,n) volatile type* name
  48. #define SYSTEM_INITIALISE_GLOBAL_ARRAY1(type,name,num,val) \
  49.           { \
  50.         int siga1; \
  51.         name=(volatile type*)(system_static_malloc(sizeof(type)*num)); \
  52.         for (siga1=0;siga1<num;++siga1) { \
  53.           *(name+siga1)=val; \
  54.         } \
  55.       }
  56. #define SYSTEM_GLOBAL_ARRAY1_VALUE(name,index) (*(name+index))
  57. #define ADD_SYSTEM_GLOBAL_ROOT(name) add_root(name)
  58.  
  59. #endif
  60.  
  61. /* ******************************************************************** */
  62. /*                             Any Machine                              */
  63. /* ******************************************************************** */
  64.  
  65. #ifdef MACHINE_ANY
  66.  
  67. typedef int SystemSemaphore;
  68.  
  69. #define SYSTEM_THREAD_SPECIFIC_DECLARATION(type,name) type name
  70. #define SYSTEM_THREAD_SPECIFIC_VALUE(name) (name)
  71.  
  72. #define SYSTEM_GLOBAL(type,name) type name
  73. #define SYSTEM_GLOBAL_VALUE(name) (name)
  74. #define SYSTEM_INITIALISE_GLOBAL(type,name,value) name=value
  75. #define SYSTEM_GLOBAL_ARRAY1(type,name,dim) type name[dim]
  76. #define SYSTEM_INITIALISE_GLOBAL_ARRAY1(type,name,num,val) \
  77.           { \
  78.         int siga1; \
  79.         for (siga1=0;siga1<num;++siga1) { \
  80.           *(name+siga1)=val; \
  81.         } \
  82.       }
  83. #define SYSTEM_GLOBAL_ARRAY1_VALUE(name,index) (name[index])
  84. #define ADD_SYSTEM_GLOBAL_ROOT(name) add_root(&name)
  85. #endif
  86.  
  87. /* ******************************************************************** */
  88. /*                               BSD                                    */
  89. /* ******************************************************************** */
  90.  
  91. #ifdef MACHINE_BSD
  92.  
  93. typedef int SystemSemaphore;
  94.  
  95. #define SYSTEM_THREAD_SPECIFIC_DECLARATION(type,name) type name
  96. #define SYSTEM_THREAD_SPECIFIC_VALUE(name)            (name)
  97.  
  98. #define SYSTEM_GLOBAL(type,name)            type name
  99. #define SYSTEM_INITIALISE_GLOBAL(type,name,value) (name=value)
  100. #define SYSTEM_GLOBAL_VALUE(name)           (name)
  101. #define SYSTEM_GLOBAL_ARRAY1(type,name,n) type name[n]
  102. #define SYSTEM_INITIALISE_GLOBAL_ARRAY1(type,name,num,val) \
  103.           { \
  104.         int siga1; \
  105.         for (siga1=0;siga1<num;++siga1) { \
  106.           *(name+siga1)=val; \
  107.         } \
  108.       }
  109. #define SYSTEM_GLOBAL_ARRAY1_VALUE(name,index) (name[index])
  110. #define ADD_SYSTEM_GLOBAL_ROOT(name) add_root(&name)
  111. #endif
  112.  
  113. /*
  114.   * Stack ckecking
  115. */
  116. #define NSIGNALS 32
  117. #define REGISTER_SIGNAL(flag,n) ((flag)|=1<<(n))
  118. #define GOT_SIGNAL(flag,n) ((flag)&(1<<(n)))
  119. #define UNREGISTER_SIGNAL(flag,n) ((flag)&=~(1<<n))
  120. /* I-thread gets hit with signals */
  121. extern SYSTEM_GLOBAL(int,system_interrupt_flag);
  122.  
  123.  
  124. #define THREAD_STACK_MARGIN (3*1024)
  125. #define THREAD_GC_STACK_MARGIN (512)
  126.  
  127. #ifdef CHECK_KEYBOARD
  128. #define ON_CHECK_KBD(x) x
  129. #else 
  130. #define ON_CHECK_KBD(x)
  131. #endif
  132.  
  133. #ifdef MACHINE_ANY
  134. #define ON_NOTANY(x) 
  135. #else
  136. #define ON_NOTANY(x) x
  137. #endif
  138.  
  139. #define STACKS_OK_P(stacktop,form)    \
  140. {                    \
  141.   int handle;                \
  142.     /**/                \
  143.   ON_CHECK_KBD(                \
  144.     {                    \
  145.       static int eval_loops;        \
  146.     if (eval_loops++ == CHECK_KEYBOARD) \
  147.       {  eval_loops = 0;        \
  148.      if (kbhit())            \
  149.        if (getkey() == 17)        \
  150.          system_control_catcher(2); \
  151.        }                \
  152.   }                    \
  153.  )        \
  154.     \
  155.   if (SYSTEM_GLOBAL_VALUE(system_interrupt_flag)) \
  156.     system_handle_interrupts(stacktop,0);    \
  157.       \
  158.    ON_NOTANY(if ((int) &handle - (int) (STACK_BASE()) < THREAD_STACK_MARGIN) \
  159.     CallError(stacktop,"SYSTEM: C stack overflowing",form,NONCONTINUABLE); \
  160.     )        \
  161.       \
  162.   if (thread_gc_stack_size((CURRENT_THREAD()))              \
  163.       - (int) (stacktop-GC_STACK_BASE()) * sizeof(LispObject)    \
  164.       < THREAD_GC_STACK_MARGIN)                        \
  165.     {                                    \
  166.       CallError(stacktop,"SYSTEM: GC stack overflowing",form,NONCONTINUABLE); \
  167.     }                                    \
  168. }
  169.  
  170. #endif /* SYSTEM_T_H */
  171.  
  172.